/**
 * Creates a DirectionsRequest and passes it to Google Directions API. DirectionsResult is returned and is displayed by Directions Display.
 * @author Joshua Poole
 */


function calcRoute(position, end) {
	//Sets the map
	var directionsDisplay;
	var directionsService = new google.maps.DirectionsService();
	var map;
	directionsDisplay = new google.maps.DirectionsRenderer();
  	var gatech = new google.maps.LatLng(33.776204, -84.388937);
  	var myOptions = {
    	zoom:7,
    	mapTypeId: google.maps.MapTypeId.ROADMAP,
    	center: gatech
  	}
  	map = new google.maps.Map(document.getElementById("directions_map_canvas"), myOptions);
  	directionsDisplay.setMap(map);
  	
  	//Pulls current location coordinates into variable
	var startLat = position.coords.latitude;
	var startLong = position.coords.longitude;
	var startLocation = startLat +","+ startLong;
	
	//Gets destination coordinates from JSON
	var endLat = end["latitude"];
	var endLong = end["longitude"];
	var endLocation = endLat + "," + endLong;
	
	//Creates request to send to google for directions
  	var request = {
    	origin: startLocation,
    	destination: endLocation,
    	travelMode: google.maps.TravelMode.DRIVING,
    	unitSystem: UnitSystem.IMPERIAL
  	};
  	directionsService.route(request, function(result, status) {
    if (status == google.maps.DirectionsStatus.OK) {
      	directionsDisplay.setDirections(result);
    }
  	});
}